package com.jerry.base.java8.closure;

/**
 * 闭包1
 *
 * @author Jerry
 * @since 2024/7/31 20:55
 */
public class ClosureTest1 {

    @FunctionalInterface
    interface Lambda {
        int operate(int y);
    }

    static void highOrder(Lambda lambda) {
        System.out.println(lambda.operate(1));
    }

    public static void main(String[] args) {
        int x = 10;
        highOrder(y -> x + y);
    }

    static int a = 1;
    int b = 2;

    public void test(int c) {
        highOrder(y -> a + y);
        highOrder(y -> b + y);
        highOrder(y -> c + y);
    }

    static class Student {
        int age;

        public Student(int age) {
            this.age = age;
        }
    }

    public void test2() {
        Student student = new Student(18);
        highOrder(y -> student.age + y);
        student.age = 20;
    }
}
